package com.baseframe.advert.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baseframe.advert.entity.SnsAdvert;
import com.baseframe.advert.entity.request.SnsAdvertRequest;
import com.baseframe.advert.entity.vo.SnsAdvertVO;
import com.baseframe.advert.mapper.SnsAdvertMapper;
import com.baseframe.advert.service.SnsAdvertService;
import com.baseframe.advert.sign.AdvertType;
import com.baseframe.mybatis.utils.PageInfo;
import com.baseframe.mybatis.utils.PageUtil;
import org.springframework.stereotype.Service;

/**
 * 广告表数据库操作的Service实现类
 */
@Service
public class SnsAdvertServiceImpl extends ServiceImpl<SnsAdvertMapper, SnsAdvert>
        implements SnsAdvertService {

    /**
     * 分页查询广告信息
     *
     * @param pageInfo 分页信息对象
     * @param request  请求对象，包含查询条件
     * @return 返回广告信息的分页结果
     */
    @Override
    public Page<SnsAdvertVO> advertPage(PageInfo pageInfo, SnsAdvertRequest request) {
        Page<SnsAdvertVO> page = this.getBaseMapper()
                .advertPage(PageUtil.buildPage(pageInfo, SnsAdvertVO.class), request);

        // 设置广告类型名称
        for (SnsAdvertVO record : page.getRecords()) {
            record.setTypeName(AdvertType.getAdvertTypeName(record.getType()));
        }

        return page;
    }
}
